<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveRecord::Acts::Versioned</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveRecord::Acts::Versioned</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/plugins/acts_as_versioned/lib/acts_as_versioned_rb.html">
                vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Specify this act if you want to save a copy of the row in a versioned
table. This assumes there is a versioned table ready and that your model
has a version field. This works with optimisic locking if the lock_version
column is present as well.
</p>
<p>
The class for the versioned model is derived the first time it is seen.
Therefore, if you change your database schema you have to restart your
container for the changes to be reflected. In development mode this usually
means restarting WEBrick.
</p>
<pre>
  class Page &lt; ActiveRecord::Base
    # assumes pages_versions table
    acts_as_versioned
  end
</pre>
<p>
Example:
</p>
<pre>
  page = Page.create(:title =&gt; 'hello world!')
  page.version       # =&gt; 1

  page.title = 'hello world'
  page.save
  page.version       # =&gt; 2
  page.versions.size # =&gt; 2

  page.revert_to(1)  # using version number
  page.title         # =&gt; 'hello world!'

  page.revert_to(page.versions.last) # using versioned instance
  page.title         # =&gt; 'hello world'

  page.versions.earliest # efficient query to find the first version
  page.versions.latest   # efficient query to find the most recently created version
</pre>
<p>
Simple Queries to page between versions
</p>
<pre>
  page.versions.before(version)
  page.versions.after(version)
</pre>
<p>
Access the previous/next versions from the versioned model itself
</p>
<pre>
  version = page.versions.latest
  version.previous # go back one version
  version.next     # go forward one version
</pre>
<p>
See <a
href="Versioned/ClassMethods.html#M000029">ActiveRecord::Acts::Versioned::ClassMethods#acts_as_versioned</a>
for configuration options
</p>

    </div>


   </div>


  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Versioned/ActMethods.html" class="link">ActiveRecord::Acts::Versioned::ActMethods</a><br />
Module <a href="Versioned/ClassMethods.html" class="link">ActiveRecord::Acts::Versioned::ClassMethods</a><br />

    </div>

    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">CALLBACKS</td>
          <td>=</td>
          <td class="context-item-value">[:set_new_version, :save_version_on_create, :save_version?, :clear_changed_attributes]</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>